<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
	<title>流程职责管理</title>
	<meta name="decorator" content="ani"/>
	<script type="text/javascript">

		$(document).ready(function() {

			$("#commit").click(function () {
				var isValidate = jp.validateForm('#inputForm');//校验表单
				if(!isValidate){
					jp.error("必填项不能为空，请检查！");
					return false;
				}else{
					$('#inputForm').find(".form_money").each(function(){
						$(this).val(jp.fromFloat($(this).val()));
					});
					jp.loading()
					jp.post("${ctx}/actnode/actWorflow/save",$('#inputForm').serialize(),function(data){
						if(data.success){
							jp.success(data.msg);
							history.go(-1);
						}else{
							jp.error(data.msg);
							return false;
						}
					})
				}
			})


		});

		function addRow(list, idx, tpl, row){
			$(list).append(Mustache.render(tpl, {
				idx: idx, delBtn: true, row: row
			}));
			$(list+idx).find("select").each(function(){
				$(this).val($(this).attr("data-value"));
			});
			$(list+idx).find("input[type='checkbox'], input[type='radio']").each(function(){
				var ss = $(this).attr("data-value").split(',');
				for (var i=0; i<ss.length; i++){
					if($(this).val() == ss[i]){
						$(this).attr("checked","checked");
					}
				}
			});
			$(list+idx).find(".form_datetime").each(function(){
				 $(this).datetimepicker({
					 format: "YYYY-MM-DD HH:mm:ss"
			    });
			});
		}
		function delRow(obj, prefix){
			var id = $(prefix+"_id");
			var delFlag = $(prefix+"_delFlag");
			if (id.val() == ""){
				$(obj).parent().parent().remove();
			}else if(delFlag.val() == "0"){
				delFlag.val("1");
				$(obj).html("&divide;").attr("title", "撤销删除");
				$(obj).parent().parent().addClass("error");
			}else if(delFlag.val() == "1"){
				delFlag.val("0");
				$(obj).html("&times;").attr("title", "删除");
				$(obj).parent().parent().removeClass("error");
			}
		}
	</script>
</head>
<body>
<div class="wrapper wrapper-content">
	<div class="row">
		<div class="col-md-12">
			<div class="panel panel-primary">
				<div class="panel-heading">
					<h3 class="panel-title">
						<a class="panelButton" href="${ctx}/actnode/actWorflow"><i class="ti-angle-left"></i> 返回</a>
					</h3>
				</div>
				<div class="panel-body">
					<form:form id="inputForm" modelAttribute="actWorflow" action="${ctx}/actnode/actWorflow/save" method="post" class="form-horizontal">
						<form:hidden path="id"/>
						<form:hidden path="key"/>
						<fieldset>
							<legend><i style="padding: 0px 5px 0px 5px" class="fa fa-hand-o-right" aria-hidden="true"></i>基本信息</legend>
							<div class="form-group">
								<label class="col-sm-2 col-md-1 control-label">流程名称：</label>
								<div class="col-sm-10 col-md-2">
									<sys:gridselect url="${ctx}/basedata/actFlow/actFlow/data" id="worklow"
													name="worklow.id" value="${actWorflow.worklow.id}" labelName="worklow.fFullname" labelValue="${actWorflow.worklow.fFullname}"
													title="选择流程名称" cssClass="form-control required"
													fieldLabels="流程名称|标识|版本"
													fieldKeys="name|key|version"
													searchLabels="流程名称" searchKeys="name"
													relationName="key,key"
									></sys:gridselect>
								</div>
								<label class="col-sm-2 col-md-1 control-label">展示顺序：</label>
								<div class="col-sm-10 col-md-2">
									<form:input path="sort" htmlEscape="false"    class="form-control "/>
								</div>
								<label class="col-sm-2 col-md-1 control-label">表名：</label>
								<div class="col-sm-10 col-md-2">
									<form:input path="tablea" htmlEscape="false"    class="form-control "/>
								</div>
								<label class="col-sm-2 col-md-1 control-label">备注：</label>
								<div class="col-sm-10 col-md-2">
									<form:input path="remarks" htmlEscape="false"    class="form-control "/>
								</div>
							</div>
						</fieldset>
						<fieldset>
							<legend><i style="padding: 0px 5px 0px 5px" class="fa fa-hand-o-right" aria-hidden="true"></i>流程节点</legend>
								<div class="tabs-container">
									<div class="tab-content">
										<div id="tab-1" class="tab-pane fade in  active">
											<a class="btn btn-white btn-sm" onclick="addRow('#actWorflownodeList', actWorflownodeRowIdx, actWorflownodeTpl);actWorflownodeRowIdx = actWorflownodeRowIdx + 1;" title="新增"><i class="fa fa-plus"></i> 新增</a>
												<table class="table table-striped table-bordered table-condensed">
													<thead>
														<tr>
															<th class="hide"></th>
															<th>节点名称</th>
															<th>岗位职责描述</th>
															<th>排序</th>
															<th>预计用时</th>
															<th>备注</th>
															<th width="10">&nbsp;</th>
														</tr>
													</thead>
													<tbody id="actWorflownodeList">
													</tbody>
												</table>
											<script type="text/template" id="actWorflownodeTpl">//<!--
												<tr id="actWorflownodeList{{idx}}">
													<td class="hide">
														<input id="actWorflownodeList{{idx}}_id" name="actWorflownodeList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
														<input id="actWorflownodeList{{idx}}_delFlag" name="actWorflownodeList[{{idx}}].delFlag" type="hidden" value="0"/>
													</td>
													<td>
													    <textarea id="actWorflownodeList{{idx}}_actnode" name="actWorflownodeList[{{idx}}].actnode"   class="form-control ">{{row.actnode}}</textarea>
													</td>
													<td>
														<textarea id="actWorflownodeList{{idx}}_workcontent" name="actWorflownodeList[{{idx}}].workcontent"   class="form-control ">{{row.workcontent}}</textarea>
													</td>
													<td>
														<textarea id="actWorflownodeList{{idx}}_sort" name="actWorflownodeList[{{idx}}].sort"   class="form-control ">{{row.sort}}</textarea>
													</td>
													<td>
														<textarea id="actWorflownodeList{{idx}}_time" name="actWorflownodeList[{{idx}}].time"   class="form-control ">{{row.time}}</textarea>
													</td>
													<td>
														<textarea id="actWorflownodeList{{idx}}_remarks" name="actWorflownodeList[{{idx}}].remarks"   class="form-control ">{{row.remarks}}</textarea>
													</td>
													<td class="text-center" width="10">
														{{#delBtn}}<span class="close" onclick="delRow(this, '#actWorflownodeList{{idx}}')" title="删除">&times;</span>{{/delBtn}}
													</td>
												</tr>//-->
										</script>
										<script type="text/javascript">
											var actWorflownodeRowIdx = 0, actWorflownodeTpl = $("#actWorflownodeTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
											$(document).ready(function() {
												var data = ${fns:toJson(actWorflow.actWorflownodeList)};
												for (var i=0; i<data.length; i++){
													addRow('#actWorflownodeList', actWorflownodeRowIdx, actWorflownodeTpl, data[i]);
													actWorflownodeRowIdx = actWorflownodeRowIdx + 1;
												}
											});
										</script>
									</div>
								</div>
							</div>
						</fieldset>
						<c:if test="${mode == 'add' || mode=='edit'}">
							<div class="col-lg-3"></div>
							<div class="col-lg-6">
								<div class="form-group text-center">
									<div>
										<input id="commit" class="btn btn-primary btn-lg btn-parsley" type="button" value="提 交"/>
									</div>
								</div>
							</div>
						</c:if>
					</form:form>
				</div>
			</div>
		</div>
	</div>
</div>
</body>
</html>


